package com.thread.thread02;

/**
 * @version: java version 23
 * @Author: 韩学新
 * @description:
 * @date: 2025-03-24 下午8:52
 */
public class ThreadCount implements Runnable {
    private int count = 100;

    @Override
    public void run() {
        while (true) {
            if (count > 0) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                count--;
                System.out.println(Thread.currentThread().getName() + ": " + count);
            }


        }

    }

    public static void main() {
        /**
         * 两个线程同时休眠，再同时开始，大概率会发生线程安全问题，用来模拟线程安全问题
         */
        ThreadCount threadCount = new ThreadCount();
        new Thread(threadCount).start();
        new Thread(threadCount).start();
    }
}
